/*
 * Copyright 1999-2004 Alibaba.com All right reserved. This software is the confidential and proprietary information of
 * Alibaba.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with Alibaba.com.
 */
package action.expr.ast;

import action.expr.ActionVisitor;
import action.expr.VisitableAction;

/**
 * һ����ֵ���
 * 
 * @author pf-miles 2011-6-17 ����03:26:41
 */
public class Assignment implements VisitableAction {

    private Field field;
    private Assignator assignator;
    private Expr expr;

    public void accept(ActionVisitor visitor, Object... params) {
        visitor.visitAssignment(this, params);
    }

    public String toString() {
        return field.toString() + " " + assignator.toString() + " " + expr.toString();
    }

    public Field getField() {
        return field;
    }

    public void setField(Field field) {
        this.field = field;
    }

    public Assignator getAssignator() {
        return assignator;
    }

    public void setAssignator(Assignator assignator) {
        this.assignator = assignator;
    }

    public Expr getExpr() {
        return expr;
    }

    public void setExpr(Expr expr) {
        this.expr = expr;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((assignator == null) ? 0 : assignator.hashCode());
        result = prime * result + ((expr == null) ? 0 : expr.hashCode());
        result = prime * result + ((field == null) ? 0 : field.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Assignment other = (Assignment) obj;
        if (assignator == null) {
            if (other.assignator != null)
                return false;
        } else if (!assignator.equals(other.assignator))
            return false;
        if (expr == null) {
            if (other.expr != null)
                return false;
        } else if (!expr.equals(other.expr))
            return false;
        if (field == null) {
            if (other.field != null)
                return false;
        } else if (!field.equals(other.field))
            return false;
        return true;
    }
}
